package com.kupurui.asteacher.ui.job;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.adapter.AllJobAdapter;
import com.kupurui.asteacher.bean.AllJobInfo;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.utils.UserManger;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 全部作业
 * Created by Administrator on 2017/7/21.
 */

public class AllJobAty extends BaseAty {

    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.listview)
    ListView listview;
    @Bind(R.id.tv_empty)
    TextView tvEmpty;

    AllJobAdapter adapter;
    List<AllJobInfo> list;

    private String id = "";

    @Override
    public int getLayoutId() {
        return R.layout.all_job_aty;
    }

    @Override
    public void initData() {
        if (getIntent().getExtras()!=null){
            id = getIntent().getStringExtra("id");
        }
        list = new ArrayList<>();
        adapter = new AllJobAdapter(this,list,R.layout.all_job_item);
        listview.setAdapter(adapter);
        listview.setEmptyView(tvEmpty);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundle = new Bundle();
                bundle.putString("id",list.get(position).getId());
                bundle.putString("class_id",list.get(position).getClass_id());
                startActivity(JobOverviewAty.class,bundle);
            }
        });
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new Teacher().totalWork(id, UserManger.getId(),this,0);
    }

    @OnClick({R.id.iv_back})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    public void intoActivity(Object object, int what) {
        super.intoActivity(object, what);
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        list.clear();
        list.addAll(AppJsonUtil.getArrayList(result,AllJobInfo.class));
        adapter.notifyDataSetChanged();
        super.onSuccess(result, call, response, what);
    }
}
